package cn.skyisazure.metacompare.sqlcompare.utils;

import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.StrUtil;

/**
 * @author wangjj
 * @date 2025/3/20 下午4:58
 */
public class DDLConstant {

    public static final String DEFAULTCOLLATE = "utf8mb4_unicode_ci";
    public static final String DEFAULTCHARSET = "utf8mb4";
    private String template;

    public DDLConstant(String template) {
        this.template = template;
    }

    public static final DDLConstant CREATE_DATA_SOURCE = new DDLConstant("CREATE DATABASE IF NOT EXISTS `?` DEFAULT CHARACTER SET {DEFAULTCHARSET} DEFAULT COLLATE {DEFAULTCOLLATE};");
    public static final DDLConstant DROP_DATA_SOURCE = new DDLConstant("DROP DATABASE IF EXISTS `?`;");
    /** 数据查询 是否存在某些列的重复数据，返回boolean值 */
    public static final DDLConstant DATA_COLUMN_IS_REPEAT_DATA = new DDLConstant("select count(1) from ? WHERE ? group by ? having count(1)>1 ;");



    public String format(Object... param) {
        /*默认编码*/
        this.template = this.template.replace("{DEFAULTCHARSET}", DEFAULTCHARSET).replace("{DEFAULTCOLLATE}", DEFAULTCOLLATE);
        return StrFormatter.formatWith(template, "?", param);
    }


}
